home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / libnet-dbus-perl / examples / example-service-async.pl < prev    next >
Encoding:
Perl Script  |  2008-02-20  |  1.3 KB  |  61 lines

  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. use Carp qw(confess cluck);
  7. use Net::DBus;
  8. use Net::DBus::Service;
  9. use Net::DBus::Reactor;
  10.  
  11. #...  continued at botom
  12.  
  13.  
  14. package SomeObject;
  15.  
  16. use base qw(Net::DBus::Object);
  17. use Net::DBus::Exporter qw(org.designfu.SampleInterface);
  18.  
  19. sub new {
  20.     my $class = shift;
  21.     my $service = shift;
  22.     my $self = $class->SUPER::new($service, "/SomeObject");
  23.     bless $self, $class;
  24.  
  25.     return $self;
  26. }
  27.  
  28. dbus_method("HelloWorld", ["string"], [["array", "string"]]);
  29. sub HelloWorld {
  30.     my $self = shift;
  31.     my $message = shift;
  32.     print "Do hello world\n";
  33.     print $message, "\n";
  34.     sleep 10;
  35.     return ["Hello", " from example-service-async.pl"];
  36. }
  37.  
  38. dbus_method("GetDict", [], [["dict", "string", "string"]]);
  39. sub GetDict {
  40.     my $self = shift;
  41.     print "Do get dict\n";
  42.     sleep 10;
  43.     return {"first" => "Hello Dict", "second" => " from example-service.pl"};
  44. }
  45.  
  46. dbus_method("GetTuple", [], [["struct", "string", "string"]]);
  47. sub GetTuple {
  48.     my $self = shift;
  49.     print "Do get tuple\n";
  50.     sleep 10;
  51.     return ["Hello Tuple", " from example-service.pl"];
  52. }
  53.  
  54. package main;
  55.  
  56. my $bus = Net::DBus->session();
  57. my $service = $bus->export_service("org.designfu.SampleService");
  58. my $object = SomeObject->new($service);
  59.  
  60. Net::DBus::Reactor->main->run();
  61.